from aiogram_dialog import DialogManager

from src.database.services.product import ProductService


async def available_products_getter(dialog_manager: DialogManager, **kwargs):
    product_service: ProductService = dialog_manager.middleware_data.get(
        "product_service"
    )
    category_id: int = dialog_manager.dialog_data.get("category_id")

    products = await product_service.get_available_products(category_id)
    products_count = len(products)
    dialog_manager.dialog_data["products_count"] = products_count

    return {
        "products_count": products_count,
    }
